﻿using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using UDS.Components;

namespace UDS.Inc
{
    /// <summary>
    ///	ControlClientContactHistory 的摘要说明。
    /// </summary>
    public partial class ControlClientContactHistory_thisWeek : UserControl
    {
        public new int ClientID
        {
            get;
            set;
        }

        public void BindData()
        {
            var cm = new CM();
            var ds = new DataSet();
            DataTable dt;
            using (SqlDataReader dr = cm.GetClientContactInfo_thisWeek(ClientID))
            {
                dt = Tools.ConvertDataReaderToDataTable(dr);
            }
            dt.TableName = "ClientContact";
            ds.Tables.Add(dt);

            var staff = new Staff();
            DataTable dt1;
            using (SqlDataReader dr_staff = staff.GetTotalStaffs())
            {
                dt1 = Tools.ConvertDataReaderToDataTable(dr_staff);
            }
            dt1.TableName = "Staffs";
            ds.Tables.Add(dt1);

            DataTable dt2;
            using (SqlDataReader dr_linkman = cm.GetAllContactLinkman())
            {
                dt2 = Tools.ConvertDataReaderToDataTable(dr_linkman);
            }
            dt2.TableName = "Linkman";
            ds.Tables.Add(dt2);

            DataTable dt3;
            using (SqlDataReader dr_cooperater = cm.GetAllCooperater())
            {
                dt3 = Tools.ConvertDataReaderToDataTable(dr_cooperater);
            }
            dt3.TableName = "Cooperater";
            ds.Tables.Add(dt3);

            DataTable dt4;
            using (SqlDataReader dr_att = cm.GetAttachmentByContactID(0))
            {
                dt4 = Tools.ConvertDataReaderToDataTable(dr_att);
            }
            dt4.TableName = "Attachment";
            ds.Tables.Add(dt4);
            ds.Relations.Add("ContactMarketman_Staffs", ds.Tables["Staffs"].Columns["Staff_ID"], ds.Tables["ClientContact"].Columns["MarketmanID"], false);
            ds.Relations.Add("Contact_Linkman", ds.Tables["ClientContact"].Columns["ID"], ds.Tables["Linkman"].Columns["ContactID"], false);
            ds.Relations.Add("Contact_Cooperater", ds.Tables["ClientContact"].Columns["ID"], ds.Tables["Cooperater"].Columns["ContactID"], false);
            ds.Relations.Add("Contact_Attachment", ds.Tables["ClientContact"].Columns["ID"], ds.Tables["Attachment"].Columns["pertainid"], false);
            //ds.Relations.Add("ContactLinkman_Staffs",ds.Tables["Staffs"].Columns["Staff_ID"],ds.Tables["Linkman"].Columns["LinkmanID"],false);
            //ds.Relations.Add("ContactCooperater_Staffs",ds.Tables["Staffs"].Columns["Staff_ID"],ds.Tables["Cooperater"].Columns["CooperatingmanID"],false);
            rpt_data.DataSource = ds.Tables["ClientContact"].DefaultView;
            rpt_data.DataBind();
        }
    }
}